<%--
  Created by IntelliJ IDEA.
  User: xianfei
  Date: 15-1-13
  Time: 上午11:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>度假屋基地</title>
    <script src="/static/bootstrap/js/bootstrap-paginator.js"></script>
    <script>
        $(function () {

            $("td.FT").each(function () {
                var FT = $(this).text().toString();
                if (FT == "false") {
                    $(this).text("否");
                }
                if (FT == "true") {
                    $(this).text("是");
                }
            });


            var a = $("[id^=info]");
            for (var i = 0; i < a.length; i++) {
                var str = a.eq(i).html().substr(0, 5);
                $("#info_" + i).html(str + '...');
            }
            var b = $("[id^=intro]");
            for (var i = 0; i < b.length; i++) {
                var str = b.eq(i).html().substr(0, 5);
                $("#intro_" + i).html(str + '...');
            }

            $("#check").hover(function () {
                $(this).css({cursor: "url(),pointer"});
            });

            var totalPage = $("#totalPage").val();
            var currentPage = $("#currentPage").val();
            var options = {
                bootstrapMajorVersion: 3,
                currentPage: currentPage,
                totalPages: totalPage,
                size: "normal",
                alignment: "center",
                itemTexts: function (type, page, current) {
                    switch (type) {
                        case "first":
                            return "首页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "末页";
                        case "page":
                            return page;
                    }
                },
                onPageClicked: function (e, originalEvent, type, page) {
                    window.location.href = '/house/houseBase/list/' + page;
                }
            }
            $("#pager").bootstrapPaginator(options);

        });

        function addHouseBase() {
            window.location.href = "/house/houseBase/form";
        }

        function deleteHouseBase(guid) {
            $.ajax({
                url: "/house/houseBase/beforeDelete",
                data: "guid=" + guid,
                dataType: "json",
                success: function (data) {
                    if (data == "false") {
                        if (confirm("确定要删除吗")) {
                            $.ajax({
                                url: "/house/houseBase/delete",
                                data: "guid=" + guid,
                                type: "POST",
                                success: function () {
                                    location.reload();
                                }
                            });
                        }
                    } else {
                        $.ajax({
                            url: "/house/houseBase/delete",
                            data: "guid=" + guid,
                            type: "POST",
                            success: function () {
                                location.reload();
                            }
                        });
                    }
                }
            })
        }

        function showHouseType(houseBaseGuid) {
            location.href = "/house/houseType/list/" + houseBaseGuid;
        }

        function sortHouse(index, guid) {
            var value = $("#sort" + index).val();
            $.ajax({
                url: "/house/houseBase/sort/" + value + "/" + guid,
                dataType: "json",
                success: function (data) {

                }
            })
        }
    </script>
</head>
<body>
<div>
    <button type="button" class="btn btn-warning" onclick="addHouseBase()" title="添加度假屋基地">新增</button>
    <table class="table table-striped" style="height: 45px;">
        <thead>
        <tr>
            <th>类型</th>
            <th>名字</th>
            <th>介绍</th>
            <th>详情</th>
            <th>价格(元)</th>
            <th>户型数</th>
            <th>是否精选</th>
            <%--<th>图片</th>--%>
            <th>排序</th>
            <th>操作</th>
        <tr>
        </thead>
        <tbody>
        <c:forEach items="${houseBaseList}" var="list" varStatus="status">
            <tr>
                <td><c:if test="${list.productType=='HOUSEBASE'}">别墅</c:if><c:if
                        test="${list.productType=='APARTMENT'}">公寓</c:if></td>
                <td>${list.title}</td>
                <td id="intro_${status.index}" title="${list.introduction}">${list.introduction}</td>
                <td id="info_${status.index}" title="${list.information}">${list.information}</td>
                <td>${list.price}</td>
                <td><span id="check" onclick="showHouseType('${list.guid}')" title="点击查看户型">${list.houseTypeNum}</span>
                </td>
                <td class="FT">${list.fineTheme}</td>
                <%--<td>--%>
                    <%--<c:forEach items="${list.imageGuids}" var="images">--%>
                        <%--<img src="/public/img/${images}/50/70" style="width:50px;height:70px">--%>
                    <%--</c:forEach>--%>
                <%--</td>--%>
                <td>
                    <input type="text" width="10" id="sort${status.index}"
                           onclick="sortHouse('${status.index}','${list.guid}')"/>
                </td>
                <td><a href="/house/houseType/form/${list.guid}" title="添加户型">添加户型</a>&nbsp;
                    <a href="/house/houseBase/beforeUpdate/${list.guid}" title="修改基地信息">修改</a>&nbsp;
                    <a href="javascript:void(0)" onclick="deleteHouseBase('${list.guid}')" title="删除该度假屋基地">删除</a></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
<div>
    <input type="hidden" id="totalPage" value="${totalPage}">
    <input type="hidden" id="currentPage" value="${currentPage}">
    <ul id="pager"></ul>
</div>
</body>
</html>